﻿using System;
using System.Web.UI;
using GUI.Extensions;

namespace GUI.Controls.News
{
    public partial class SearchNewsByDate : System.Web.UI.UserControl
    {
        private const int StartYear = 2010;
        private const string OptionFormat = "<option value=\"{0}\">{1}</option>";
        private const string SelectedOptionFormat = "<option value=\"{0}\" selected=\"selected\">{1}</option>";
        protected void Page_Load(object sender, EventArgs e)
        {
            
            Page.ClientScript.RegisterHiddenField("hidCatUrl", RequestExtensions.CatUrl);
            var day = RequestExtensions.Day;
            var month = RequestExtensions.Month;
            var year = RequestExtensions.Year;
            {
                var sb = new System.Text.StringBuilder();
                sb.Append(string.Format(
                        day <= 0 ? SelectedOptionFormat : OptionFormat,
                        0, "ngày"
                        ));
                for (var i = 1; i <= 31; i++)
                {
                    sb.Append(string.Format(
                        day == i ? SelectedOptionFormat : OptionFormat,
                        i, i
                        ));
                }
                ltrDay.Text = sb.ToString();
            }

            {
                var sb = new System.Text.StringBuilder();
                sb.Append(string.Format(
                        month <= 0 ? SelectedOptionFormat : OptionFormat,
                        0, "tháng"
                        ));
                for (var i = 1; i <= 12; i++)
                {
                    sb.Append(string.Format(
                        month == i ? SelectedOptionFormat : OptionFormat,
                        i, i
                        ));
                }
                ltrMonth.Text = sb.ToString();
            }

            {
                var sb = new System.Text.StringBuilder();
                sb.Append(string.Format(
                        year <= 0 ? SelectedOptionFormat : OptionFormat,
                        0, "năm"
                        ));
                for (var i = StartYear; i <= DateTime.Now.Year; i++)
                {
                    sb.Append(string.Format(
                        year == i ? SelectedOptionFormat : OptionFormat,
                        i, i
                        ));
                }
                ltrYear.Text = sb.ToString();
            }

        }
    }
}
